import axios from 'axios'
import router from '../router'
import store from '../store'
let http = axios.create({
    baseURL: '/api'
})

//创建请求拦截器
http.interceptors.request.use((req) => {
    console.log(req, 555)
    // if (req.url != '/userlogin') {
    //     req.headers.authorization = store.getters.getUserInfo.token;
    // }

    return req
})

//创建响应拦截器
http.interceptors.response.use((res) => {
    if (res.data.msg == '请设置请求头,并携带验证字符串') {
        alert(res.data.msg)
        router.push('/login')
    } else if (res.data.msg == '登录已过期或访问权限受限') {
        alert(res.data.msg)
        router.push('/login')
    } else {
        return res.data
    }
})

export default http